What is the meaning of the word "judge advocate"?

Definitions:

  1. a staff officer serving as legal adviser to a military commander copy to clipboard noun
    • The judge advocate made sure the commander's orders were legal. copy to clipboard
  2. an officer assigned to the judge advocate general copy to clipboard noun
    • The judge advocate prosecuted the solider for war crimes. copy to clipboard